//
//  SISSModelContractWebViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2017/10/23.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSModelContractWebViewController.h"
#import <WebKit/WebKit.h>

@interface SISSModelContractWebViewController ()

/// webView
@property (nonatomic, strong) WKWebView *webView;

@end

@implementation SISSModelContractWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)setupSubviews {
    [super setupSubviews];
    
    WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
    
    // 自适应屏幕宽度js
    NSString *jSString = @"var script = document.createElement('script');"
    "script.type = 'text/javascript';"
    "script.text = \"function ResizeImages() { "
    "var myimg,oldwidth,oldheight;"
    "var maxwidth=320;" // 图片宽度
    "for(i=0;i  maxwidth){"
    "myimg.width = maxwidth;"
    "}"
    "}"
    "}\";"
    "document.getElementsByTagName('head')[0].appendChild(script);";
    WKUserScript *wkUserScript = [[WKUserScript alloc] initWithSource:jSString injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
    // 添加自适应屏幕宽度js调用的方法
    WKUserContentController *wkUController = [[WKUserContentController alloc] init];
    [wkUController addUserScript:wkUserScript];
    wkWebConfig.userContentController = wkUController;
    
    WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:wkWebConfig];
    [self.view addSubview:webView];
    self.webView = webView;
    
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",WEB_BASE_URL,self.url];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[urlString URLEncodeString]]];
    
//    [request setValue:[NSString stringWithFormat:@"%@ %@",[SISSUserAccount shared].token_type,[SISSUserAccount shared].access_token] forHTTPHeaderField:@"Authorization"];

    request.timeoutInterval = 15.0f;
    [self.webView loadRequest:request];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
